package com.yc.springcloud.controller;

import com.yc.springcloud.entity.Member;
import com.yc.springcloud.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author DELL
 * @Date 2024/10/18 0:44
 * @Version 1.0
 */
@Controller
@Slf4j
public class MemberNacosConsumerController {

	/**
	 * 老师说明: http://member-service-nacos-provider Nacos要求这里的服务名要小写,和服
	 务 Nacos Server 中注册名保持一致
	 */
	public static final String MEMBER_SERVICE_NACOS_PROVIDER_URL =
			"http://member-service-nacos-provider";
	@Resource
	private RestTemplate restTemplate;

	@ResponseBody
	@GetMapping(value = "/member/nacosconsumer/get/{id}")
	public Result<Member> queryMemberById(@PathVariable("id") Long id){

		log.info("id=",id);
		//访问member_service_provider-001 的queryMemberById接口
		// String MEMBER_SERVICE_PROVIDER_URL =
		// 		MEMBER_SERVICE_NACOS_PROVIDER_URL + "/member/get/" + id;

		log.info(MEMBER_SERVICE_NACOS_PROVIDER_URL + "/member/get/" + id);
		return restTemplate.getForObject(MEMBER_SERVICE_NACOS_PROVIDER_URL + "/member/get/" + id,Result.class);

	}


}
